<?php
namespace Tbf\Bundle\YntAuthBundle\Service;
use Tbf\Bundle\SerializerBundle\Handler\ClassNameAwareHandlerInterface;
use Tbf\Bundle\SerializerBundle\Handler\NewFromArray\NewFromArrayInterface;
use Tbf\Bundle\SerializerBundle\Serializer;
use Tbf\Bundle\SerializerBundle\SerializerAware;

class UserSerializer extends SerializerAware implements NewFromArrayInterface,ClassNameAwareHandlerInterface{
    public function newFromArray($class_name, $input,$group=null)
    {
        $obj = $this->serializer->newInstanceWithoutConstructor($class_name);

        $meta_class = $this->serializer->getReflectionClass(get_class($obj));
        foreach ($meta_class->getProperties() as $meta_property) {
            $name = $meta_property->getName();
            if (array_key_exists($name,$input)) {
                $meta_property->setAccessible(true);
                $meta_property->setValue($obj,$input[$name]);
                unset($input[$name]);
            }
        }

        /** @var \Tbf\Bundle\YntAuthBundle\Model\User $obj*/
        $obj->setExtraData($input);
        return $obj;
    }

    /**
     * @return string
     */
    static function getSerializeClassName()
    {
        return '\Tbf\Bundle\YntAuthBundle\Model\User';
    }

}